﻿@{
    ViewBag.Title = "GroupIndex";
    Layout = "~/Views/Shared/Houyun.cshtml";
}
<script>
    //点击头条的信息
    function gaitou(id) {
        var str = "";
        if ($(this).prop("class") == "label label-success") {
            str += "";
        }
        else {
            str += "头条";
        }             
        //修改属性
        $.post("/Group/editattr", { id: id, str: str }, function (data) {
            if (data == "1") {
                location.reload();
            }
        })
    }
    //点击推荐
    function gaitui(id) {
        var str = "";
        if ($(this).prop("class") == "label label-success") {
            str += "";
        }
        else {
            str += "推荐";
        }      
        //修改属性
        $.post("/Group/editattr", { id: id, str: str }, function (data) {
            if (data == "1") {
                location.reload();
            }

        })
    }
    //点击置顶
    function gaiding(id) {
        var str = "";
        if ($(this).prop("class") == "label label-success") {
            str += "";
        }
        else {
            str += "置顶";
        }      
        //修改属性
        $.post("/Group/editattr", { id: id, str: str }, function (data) {
            if (data == "1") {
                location.reload();
            }

        })
    }
    //全选按钮
    $(function () {
        $('#quanxuan').click(function () {
            $('#aticle-table-container input[type="checkbox"]').prop("checked", this.checked);
        });
    })

    //批量删除
    function alldel() {
        if($('#checkbox').prop("checked")==false){
            confirm('请选择要删除的资讯')    
        }
        else{
            if (confirm('确定删除吗？')) {
                if (confirm('真的要删除吗？')) {
                    if (confirm('再给一次机会吧')) {
                        if (confirm('全删的后果是很严重的，小心你脑袋')) {
                            //获取选中的id
                            var listid = "";
                            $('#aticle-table-container :checked').each(function () {
                                listid += $(this).val() + ',';
                            })
                            listid = listid.substr(0, listid.length - 1);
                            if (listid == "") {

                            }
                            //ajax传值进行删除
                            $.ajax({
                                url: "/Group/DelInfoList",
                                type: "post",
                                data: { listid: listid },
                                success: function (result) {
                                    if (result == "1") {
                                        alert("删除成功");
                                        location.href = "/Group/GroupIndex"

                                    }
                                }

                            })
                    
                        }
                    }
                }
            }
        }

    }
  }
  
</script>


<div class="page-header clearfix">
    <h1 class="pull-left">资讯管理</h1>
    <div class="pull-right">
        <a class="btn btn-success btn-sm" href="/Group/createInfo">添加资讯</a>
    </div>
</div>

<ul class="nav nav-tabs mbm">
    <li class="active">
        <a href="/Group/GroupIndex">资讯管理</a>

    </li>
    <li>
        <a href="/Group/category">栏目管理</a>

    </li>
</ul>

<form class="well well-sm form-inline" action="/Group/GroupIndex" method="get">
    <div class="form-group">
        <select class="form-control" name="ColumnssID">
            <option value="">--所属栏目--</option>
            @foreach (var item in ViewBag.collist)
            {
                <option value="@item.ColumnssID">@item.CLNAME</option>
            }
        </select>
    </div>
    <div class="form-group">
        <input class="form-control" name="INTITLE" id="INTITLE" placeholder="输入标题的关键词" type="text">
    </div>

    <div class="form-group">
        <select class="form-control" name="ATTRIBUTE">
            <option value="">--属性--</option>
            <option value="头条">头条</option>
            <option value="推荐">推荐</option>
            <option value="置顶">置顶</option>
        </select>
    </div>
    <div class="form-group">
        <select class="form-control" name="INSTATE">
            <option value="">--发布状态--</option>
            <option value="0">已发布</option>
            <option value="1">未发布</option>
        </select>
    </div>
    <button class="btn btn-primary" type="submit">搜索</button>

</form>
<div id="aticle-table-container">

    <table class="table table-hover table-striped" id="article-table">
        <thead>
            <tr>
                <th width="10%">ID</th>
                <th width="20%">资讯标题</th>
                <th width="15%">栏目</th>
                <th width="18%">更新时间</th>
                <th width="15%">属性</th>
                <th width="7">状态</th>
                <th width="15%">操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in ViewBag.info as List<LeEdu.MODEL.Information>)
            {
                <tr>
                    <td><input name="jiancha" id="checkbox" data-role="batch-item" type="checkbox" value="@item.ID"> @item.ID</td>
                    <td>
                        <span class="text-muted"><a href="/Group/article/@item.ID" target="_blank">@item.INTITLE</a></span>
                    </td>
                    <td>
                        <span class="text-muted"><a href="/Group/GroupIA/@item.ColumnssID" target="_blank">@item.Columnss.CLNAME</a></span>
                    </td>
                    <td>@item.INOLDTIME</td>
                    <td>
                        <a href="#"><span id="t1" onclick="gaitou(@item.ID)" value="头条" class="label @(item.ATTRIBUTE.Contains("头条") ? "label-success" : "label-default")">头</span></a>

                        <a href="#"><span id="t2" class="label @(item.ATTRIBUTE.Contains("推荐") ? "label-success" : "label-default")" value="推荐" onclick="gaitui(@item.ID)">荐</span></a>

                        <a href="#"><span id="t3" class="label @(item.ATTRIBUTE.Contains("置顶") ? "label-success" : "label-default")" value="置顶" onclick="gaiding(@item.ID)">顶</span></a>

                    </td>
                    <td>
                        @(item.INSTATE == 0 ? "已发布" : item.INSTATE == 1 ? "未发布" : "回收站")
                    </td>
                    <td>
                        <div class="btn-group">
                            <a href="#" class="btn btn-default btn-sm">管理</a>
                            <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu">
                                <li><a href="/Group/EditInfoState/@item.ID" data-role="publish-item" onclick="return confirm('确定要 @(item.INSTATE==0?"关闭":"发布" ) 这条资讯吗?')" data-url="#">@(item.INSTATE == 1 ? "发布" : "关闭")</a></li>
                                <li>
                                    <a href="/Group/EditInfomation/@item.ID" data-target="#InfoEdit" data-toggle="modal">编辑资讯信息</a>
                                </li>
                                <li>
                                    <a href="/Group/DelInfomation/@item.ID" onclick="return confirm('确定删除资讯 @item.INTITLE 吗？')">删除</a>
                                </li>
                            </ul>
                        </div>
                    </td>
                </tr>
            }

        </tbody>
    </table>
    <div>
        <div style="float:left">
            <a href="/Group/GroupIndex/?pageIndex=1&ColumnssID=@(ViewBag.ColumnssID)&INTITLE=@(ViewBag.INTITLE)&ATTRIBUTE=@(ViewBag.ATTRIBUTE)&INSTATE=@(ViewBag.INSTATE)" class="btn btn-default">首页</a>
            <a href="/Group/GroupIndex/?pageIndex=@((ViewBag.pageIndex-1)>1?(ViewBag.pageIndex-1):1)&ColumnssID=@(ViewBag.ColumnssID)&INTITLE=@(ViewBag.INTITLE)&ATTRIBUTE=@(ViewBag.ATTRIBUTE)&INSTATE=@(ViewBag.INSTATE)" class="btn btn-default">上一页</a>&nbsp;
            <span class="btn btn-circle-xs btn-danger ">@ViewBag.pageIndex/@ViewBag.pageCount</span>&nbsp;
            <a href="/Group/GroupIndex/?pageIndex=@((ViewBag.pageIndex+1)<ViewBag.pageCount?(ViewBag.pageIndex+1):ViewBag.pageCount)&ColumnssID=@(ViewBag.ColumnssID)&INTITLE=@(ViewBag.INTITLE)&ATTRIBUTE=@(ViewBag.ATTRIBUTE)&INSTATE=@(ViewBag.INSTATE)" class="btn btn-default">下一页</a>
            <a href="/Group/GroupIndex/?pageIndex=@ViewBag.pageCount&ColumnssID=@(ViewBag.ColumnssID)&INTITLE=@(ViewBag.INTITLE)&ATTRIBUTE=@(ViewBag.ATTRIBUTE)&INSTATE=@(ViewBag.INSTATE)" class="btn btn-default">尾页</a>
        </div>
        <div style="float:right">
            <form action="/Group/GroupIndex" method="post">
                <input id="Hidden1" type="hidden" name="ColumnssID" value="@ViewBag.ColumnssID" />
                <input id="Hidden1" type="hidden" name="INTITLE" value="@ViewBag.INTITLE" />
                <input id="Hidden1" type="hidden" name="ATTRIBUTE" value="@ViewBag.ATTRIBUTE" />
                <input id="Hidden1" type="hidden" name="INSTATE" value="@ViewBag.INSTATE" />
                <p>
                    <span style="">跳转到：</span>
                    <input class="inputwidth" type="text" name="pageIndex" id="pageIndex" value="" size="3">
                    <input id="Submit1" type="submit" value="GO" />
                </p>
            </form>
        </div>


    </div>

</div>
<div style=" clear:both">
    <label class="checkbox-inline"><input id="quanxuan" data-role="batch-select" type="checkbox"> 全选</label>
    <button class="btn btn-default btn-sm mlm" type="submit" onclick="alldel()" data-role="batch-delete" data-name="资讯" data-url="#">删除</button>
</div>
@*模态框编辑*@

<div class="modal fade" id="InfoEdit" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
        </div><!-- /.modal-content -->
    </div>
</div>
<script>
    $("#InfoEdit").on("hidden.bs.modal", function () {
        $(this).removeData("bs.modal");
    })
</script>